package org.cn.springcloudvv.base;

import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 统一响应结果
 * @param <T>
 * @see org.springframework.http.HttpStatus
 */
//@ApiModel(value = "Result",description = "统一响应结果")
public class Result<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//@ApiModelProperty(value = "响应状态值",example = "200")
	private Integer status = 0;
	//@ApiModelProperty(value = "响应消息",example = "success")
	private String message = "";

	private T data;
	//@ApiModelProperty(value = "耗时",example = "100")
	private long time = System.currentTimeMillis();
	private String server;


	public Result() {
		this.status = HttpStatus.OK.value();
		setServer(AppContext.getLocalHostIp()+":"+AppContext.server_port);
	}
	public Result(Integer status, String message, T data) {
		this.status = status;
		this.message = message;
		this.data = data;
		setServer(AppContext.getLocalHostIp()+":"+AppContext.server_port);
	}

	public Result(Integer status, String message) {
		this.status = status;
		this.message = message;
		setServer(AppContext.getLocalHostIp()+":"+AppContext.server_port);
	}


	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public static <T> Result<T> of(Integer status, String message, T data) {
		return new Result<T>(status, message, data);
	}

	public static <T> Result<T> of(Integer status, String message) {
		return Result.of(status, message, null);
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}
}
